package com.example.bbgds.test;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class VoiceActivity2 extends Activity {

    private LayoutBottom2 bottom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_voice2);

        bottom = (LayoutBottom2) findViewById(R.id.bottom);
        bottom.setVoiceActivity2(this);
        findViewById(R.id.addvoice).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                addText();
            }
        });
    }

    private Random random = new Random();

    public void addList(){
        List<DataItem> items = new ArrayList<>();
        items.add(getTag());
        items.add(getTag());
        items.add(getTag());
        bottom.addItemToList(items);
    }

    public void addItem() {
        if (random.nextInt(10) >= 5) {
            addText();
        } else {
            addTag();
        }
    }

    boolean isRight = false;

    public void addText(){
        String text = "帮我查一下去上海的机票";
        TextView textView = getTextView(this, text);
        bottom.addItem(getItem(DataItem.TYPE_TEXT, text, textView));
    }

    public DataItem getText(){
        String text = "帮我查一下去上海的机票";
        TextView textView = getTextView(this, text);
        return getItem(DataItem.TYPE_TEXT, text, textView);
    }

    public DataItem getMid(){
        String text = "帮我查一下去上海的机票";
        TextView textView = getTextView(this, text);
        return getItem(DataItem.TYPE_MID, text, textView);
    }

    public DataItem getTag(){
        String text = "测试时间你号码和\n发卡第三方";
        View textView = View.inflate(this, R.layout.layout_tag, null);
        return getItem(DataItem.TYPE_TAG, text, textView);
    }

    public void addMid(){
        String text = "帮我查一下去上海的机票";
        TextView textView = getTextView(this, text);
        bottom.addItem(getItem(DataItem.TYPE_MID, text, textView));
    }

    public void addTag(){
        String text = "测试时间你号码和\n发卡第三方";
        View textView = View.inflate(this, R.layout.layout_tag, null);
        bottom.addItem(getItem(DataItem.TYPE_TAG, text, textView));
    }


    private DataItem getItem(int type, String text, View view){
        final DataItem item = new DataItem();
        item.mType = type;
        item.mText = text;
        isRight = !isRight;
        item.isRight = isRight;
        int height = 0;
        if (view instanceof TextView) {
            height = 105;
        } else {
            height = 310;
        }
        return item;
    }

    public static TextView getTextView(Context context, String text){
        TextView textView = new TextView(context);
        textView.setText(text);
        textView.setTextColor(0xFFFFFFFF);
        textView.setBackgroundColor(0xFF256699);
        textView.setTextSize(16);
        textView.setPadding(0, 40, 0, 0);
        return textView;
    }
}
